package com.imay.live.view.custom;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;

import com.imay.live.utils.AnimationUtil;
import com.imay.live.R;
import com.imay.live.utils.ViewUtil;

/**
 * Created by jeaman on 2017/3/24.
 * 直播UI
 */

public class RoomPushNormalView extends RoomBaseView {
    private View mMoreActionRootView;   //更多按钮容器
    private View mLinkMicRedPointView;

    private OnPushActionListener mListener;
    private CheckBox live_room_iv_more;


    public RoomPushNormalView(Context context) {
        super(context);
    }

    public RoomPushNormalView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RoomPushNormalView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public RoomPushNormalView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    protected int getLayoutId() {
        return R.layout.view_room_push_normal;
    }

    protected void init(Context context) {
        super.init(context);
        mTopRootView = findViewById(R.id.live_room_rl_top);
        mActionRootView = findViewById(R.id.live_room_rl_bottom);
        mLinkMicRedPointView = findViewById(R.id.live_room_iv_mic_red_point);
        mMoreActionRootView = findViewById(R.id.live_room_ll_action_more);
        live_room_iv_more= (CheckBox) findViewById(R.id.live_room_iv_more);

        initListener();
    }

    protected void initListener() {
//        super.initListener();
//        findViewById(R.id.live_room_iv_mic).setOnClickListener(this);
        findViewById(R.id.live_room_iv_game).setOnClickListener(this);
        findViewById(R.id.live_room_iv_gift).setOnClickListener(this);
        findViewById(R.id.live_room_iv_screenshot).setOnClickListener(this);
        findViewById(R.id.live_room_iv_share).setOnClickListener(this);
        findViewById(R.id.live_room_iv_camera).setOnClickListener(this);
        findViewById(R.id.live_room_iv_beauty).setOnClickListener(this);
        live_room_iv_more.setOnClickListener(this);
    }

    //隐藏除cocos所有view
    public void hideAllViewWithoutCocos() {
        mTopRootView.setVisibility(GONE);
        mChatRootView.setVisibility(GONE);
        mActionRootView.setVisibility(GONE);
        mCloseView.setVisibility(GONE);
    }

    public void showAllView() {
        mTopRootView.setVisibility(VISIBLE);
        mChatRootView.setVisibility(VISIBLE);
        mActionRootView.setVisibility(VISIBLE);
        mCloseView.setVisibility(VISIBLE);
    }

    //设置连麦人数
    public void setLinkMicNumber(int number) {
        mLinkMicRedPointView.setVisibility(number == 0 ? GONE : VISIBLE);
    }

    public void setOnPushActionListener(OnPushActionListener pushActionListener) {
        super.setOnActionListener(pushActionListener);
        this.mListener = pushActionListener;
    }

    //切换更多按钮
    private void toggleMoreAction() {
        if (mMoreActionRootView.getVisibility() == VISIBLE) {
            mMoreActionRootView.setVisibility(GONE);
            AnimationUtil.startToBottomAnimation(mMoreActionRootView, 250, null);
            live_room_iv_more.setChecked(false);
        } else {
            mMoreActionRootView.setVisibility(VISIBLE);
            AnimationUtil.startFromBottomAnimation(mMoreActionRootView, 250, null);
            live_room_iv_more.setChecked(true);

        }
    }

    @Override
    public void setActionViewVisibility(boolean visible) {
        super.setActionViewVisibility(visible);
        int visibility = visible ? VISIBLE : INVISIBLE;
        ViewUtil.startVisibilityAnimation(mMoreActionRootView, visibility);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
            switch (v.getId()) {
                case R.id.live_room_iv_mic:
                    mListener.onLinkMicClick();
                    break;
                case R.id.live_room_iv_game:
                    mListener.onGameClick();
                    break;
                case R.id.live_room_iv_gift:
                    mListener.onGiftClick();
                    break;
                case R.id.live_room_iv_more:
                    toggleMoreAction();
                    break;
                case R.id.live_room_iv_screenshot:
                    mListener.onScreenShotClick();
                    break;
                case R.id.live_room_iv_share:
                    mListener.onShareClick();
                    break;
                case R.id.live_room_iv_camera:
                    mListener.onCameraClick();
                    break;
                case R.id.live_room_iv_beauty:
                    mListener.onBeautyClick();
                    break;
            }
    }

    public interface OnPushActionListener extends OnActionListener {
        void onLinkMicClick();
        void onGameClick();
        void onGiftClick();
        void onScreenShotClick();
        void onShareClick();
        void onCameraClick();
        void onBeautyClick();
    }
}
